{% extends 'movie/base.html' %}
{% block head %}

{% endblock %}

{% block body %}
{% load static %}

    <div class="header">
        <div class="header-inner">
            <div class="city-container" data-val="{currentcityid:50 }">
                <div class="city-list" data-val="{ localcityid: 50 }">
                    <div class="city-list-header">定位城市：<a class="js-geo-city">杭州</a></div>
                </div>
            </div>

            <div class="nav">
                <ul class="navbar">
                    <li><a href="/movie" data-act="home-click"  class="active" >首页</a></li>
                </ul>
            </div>

            <div class="user-info">
                <div class="user-avatar J-login">
                  <img src="https://p0.meituan.net/movie/7dd82a16316ab32c8359debdb04396ef2897.png">
                  <span class="caret"></span>
                  <ul class="user-menu">
                    <li><a href="javascript:void 0">登录</a></li>
                  </ul>
                </div>
            </div>
            <form target="_blank"  class="search-form" data-actform="search-click">
                <input name="kw" class="search" type="search" maxlength="32" placeholder="搜附近影院" autocomplete="off">
                <input class="submit" type="submit" value="">
            </form>
          </div>
      </div>
      <div class="header-placeholder"></div>
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-2 col-xs-12">
                <h4>电影预告片</h4>
                <video controls height=100% style="margin-top: 10px" width=100%>
                    <source src="{{ item.trailer.url }}" title="" type="video/mp4">
                </video>
            </div>
            <div class="col-md-10 col-xs-12">
{#                影片展示#}
                <div class="movie-display">
                    <div class="movie-display-content">
                        <img onmouseover="this.src='{{ item.WordCloud.url }}'" onmouseout="this.src='{{ item.poster.url }}'" id="poster" src="{{ item.poster.url }}" alt="{{ item.name }}" class="movie-display-img">
{#                        <img id="wordcloud" style="overflow: hidden; display: none" src="{{ item.WordCloud.url }}" alt="{{ item.name }}" class="movie-display-img">#}
                        <div class="movie-display-ins">
                            <p>电影名：{{ item.name }}</p>
                            <p>导演：{{ item.directors }}</p>
                            <p>演员：{{ item.casts }}</p>
                            <p>评分：{{ item.rating }}</p>
                            <p>类型：{{ item.genes }}</p>
                        </div>
                    </div>
                </div>
{#                影院选择#}
                <div class="movie-choose">
{#                    热门地区#}
                    <div class="movie-choose-hotarea">
                        <ul class="nav nav-pills" id="hotarea">
                            <li class="disabled"><a href="" >热门：</a></li>
                        </ul>
                    </div>
{#                    面包屑层级导航#}
                    <div class="movie-choose-bread">
{#                        <p>当前路径：</p>#}
                        <ol class="breadcrumb movie-choose-bread" id="bread">
                            <li class="disabled">当前路径： </li>
                            <li id="choose-city"><a href="javascript:void(0);">选择城市</a><span class="caret"></span></li>
                            <li id="choose-dis"><a href="javascript:void(0);">选择区域</a><span class="caret"></span></li>
                            <li id="choose-cine"><a href="javascript:void(0);" class="cine_">...</a><span class="caret"></span></li>
                        </ol>
                    </div>
{#                    选择日期#}
                    <div class="movie-choose-hotarea">
                        <ul class="nav nav-pills" id="choose-date">
                            <li class="disabled"><a href="javascript:void(0);">选择日期：</a></li>
                        </ul>
                    </div>
                    <hr>

{#                    展示各级选择器#}

                    <div id="movie-choose-cinema"></div>
                    <div id="movie-choose-x"><br></div>
                        {#      页脚#}
                    <hr>
                    </div>
                </div>
{#                结果展示#}
                <div></div>
            </div>
{#            <div class="col-md-1"></div>#}
        </div>



{#    #}


    <script>
// {#    选择区/县，发送到后台，提取出电影院#}
    $(document).ready(function () {
        $(document).on('click', '.dis_', function(){
            var dis = this.text;    // 区
            // console.log(dis);    // 例如:下城区
            var city = $('#choose-city a').text();    // 将
            // console.log(city);    // 例如: 杭州
            $('#choose-dis a').text(dis);    // 将区县选择按钮上的文字变成选中的区县

            $.post('/movie/cinema', {
                'city':city,
                'district': dis,
                csrfmiddlewaretoken: '{{ csrf_token }}'
            },function (data) {
    // {#                console.log(data)#}
    //             $('#cache').text(data);
                g_data[dis] = data;
                $('#movie-choose-x').html(data);
    // {#                console.log($('#cache').text())#}
            })
        });
    });
    // {#    选择电影院，显示票价#}
    $(document).on('click', '.cinema', function () {
        var id = $(this).attr('id');
        cur_cinema_id = id;
        var cinema_name = this.text;
    // {#        console.log(cinema_name);#}
        var film = $('.movie-display-img').attr('alt');
        var cur_date = $('.date_.active').attr('id');
        $('#movie-choose-x').html('<h2>正在加载数据</h2>');
        $.post('/movie/tickets', {
            csrfmiddlewaretoken: '{{ csrf_token }}',
            'pk': id,
            'film': film,
            'date': cur_date
        }, function (data) {

            $('#movie-choose-x').html(data);
            $('.cine_').text(cinema_name)


        })
    });

    // {#    选择日期#}
    $(document).on('click', '.date_', function () {
        $('.date_.active').removeClass('active');
        var that = this;
        var date = $(this).attr('id');
        var film = $('.movie-display-img').attr('alt');
        // console.log(date)
        if (cur_cinema_id != null){
            $('#movie-choose-x').html('<h2>正在加载数据</h2>');
            $.post('/movie/tickets',{
                'pk': cur_cinema_id,
                'film' : film,
                'date' : date,
                csrfmiddlewaretoken: '{{ csrf_token }}'
            }, function (data) {
                $('#movie-choose-x').html(data);
                $(that).addClass('active');
            })
        } else {
            $('#movie-choose-x').html('<h2>请先选择影院</h2>');
        }


    });

    // Ajax for search cinema
    $('.search-form').on('submit', function (event) {
        event.preventDefault();
        var city = $('#choose-city a').text();    // 市
        var dis = $('#choose-dis a').text();    // 区
        var location = $('.search').val();
        // $('.search').val = '';
        console.log("表单提交！");
        console.log(city);
        console.log(dis);
        console.log(location);
        if(city === '选择城市'){
            $('#movie-choose-x').html('<h2>请先选择城市</h2>');
            return;
        }
        if(location === ''){
            $('#movie-choose-x').html('<h2>请先填写搜索地址</h2>');
            return;
        }
        $('#movie-choose-x').html('<h2>正在查找附近影院</h2>');
        $.post('/movie/search', {
            'city':city,
            'district': dis,
            'location': location,
            csrfmiddlewaretoken: '{{ csrf_token }}'
        },function (data) {
                console.log(data);
                g_data[dis] = data;
                $('#movie-choose-x').html(data);
            })
    })
    </script>

    </script>
    <script type="application/javascript" src="{% static 'movie/js/city_alpha.js' %}"></script>
    <script src="{% static 'movie/js/districts.js' %}" type="application/javascript"></script>
    <script type="application/javascript" src="{% static 'movie/js/formatstr.js' %}"></script>
    <script type="application/javascript" src="{% static 'movie/js/movie.js' %}"></script>
{% endblock %}
